package com.lscl.rabbitmq.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/hello/{flag}")
    @Transactional
    public void hello(@PathVariable Integer flag) {
        rabbitTemplate.convertAndSend("test_exchange_confirm", "confirm", "message confirm.....");

        if (flag == 0) {
            int i = 1 / 0;
        }
        rabbitTemplate.convertAndSend("test_exchange_confirm", "confirm", "message confirm.....");
    }
}
